-
Notifications
You must be signed in to change notification settings - Fork 191
gcc: Prevent ICE on no input file #4203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
gcc: Prevent ICE on no input file #4203
Conversation
9f14789
to
801f9ac
Compare
5bd12d1
to
ece8296
Compare
* toplev.cc (lang_dependent_init): Prevent ICE on no input file. Signed-off-by: shreyas-omkar <shreyashegdeplus06@gmail.com>
ece8296
to
37210da
Compare
Heys @philberty @powerboat9 Please review and let me know any changes required. |
Your commit log is not correct and must have a title (the first line), an empty line, and then a description followed by the GNU ChangeLog part. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the commit log :)
if (name == nullptr) { | ||
fatal_error(input_location, "no input files"); | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably breaks invocations using stdin instead of a regular file. This probably needs a different fix to use stdin in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will implement the invocation using stdin.
Fixes #3523
Problem Description
Currently, invoking the
crab1
compiler front-end without providing an input source file results in an Internal Compiler Error (ICE) due to a segmentation fault.This occurs because a
NULL
pointer for the filename is passed tolang_dependent_init
and subsequently to lower-level functions likeinit_asm_output
andlrealpath
, which do not handle theNULL
value and lead to a crash.Solution
This patch introduces a check inside the
lang_dependent_init
function ingcc/toplevel.cc
. The check verifies if the input filename isnullptr
. If it is, the compiler now reports afatal_error("no input files")
and terminates gracefully.This new behavior is more robust, providing a clear error message to the user instead of an unexpected crash, and aligns better with the behavior of other GCC front-ends.
Testing
The fix was verified manually by running the compiler with no arguments and confirming that it now prints the fatal error message instead of segfaulting.
Additionally, a full
make check-rust
was run successfully to ensure that no regressions were introduced by this change.--signoff
).make check-rust
passes locally.clang-format
on the changed file.gcc/testsuite/rust/
. (Manual test performed to confirm fix).